<template>
    <view class="more-goods">
        <goods-list
            :dataList="dataList"
        ></goods-list>
		<!-- #ifdef MP-WEIXIN -->
		<view class="loading-box" v-if="loading">
			<van-loading size="24px" color="#222222" type="spinner"/><text class="text">加载中...</text>
		</view>
		<van-toast id="van-toast" />
		<!-- #endif -->
    </view>
</template>
<script>
import goodsList from "@/components/public/goods_list";
// #ifdef MP-WEIXIN
import Toast from '@/wxcomponents/vant-weapp/toast/toast.js';
// #endif
import { getproductData } from "@/api/getdata";
export default {
    name:"moregoods",
    components:{
        "goods-list":goodsList
    },
    data(){
        return {
            dataList:[],
            allData:[],
            loading:false,
        }
    },
    onLoad(){
        this._initData();
        this.$setTopBar({title:"更多商品"});
    },
    onReachBottom(){
        this.setList();
    },
    methods:{
        async _initData(){
            try {
				let _channel = this.$store.state.channel;
                uni.showLoading({title:"加载中"});
                let data = await getproductData({prod_name:"all",channel:_channel});
                this.allData = data;
                this.dataList = this.allData.splice(0,10);
                uni.hideLoading();
            } catch (e) {
                uni.hideLoading();
				// #ifdef MP-WEIXIN
				Toast.fail(e.errMsg);
				// #endif
            }
        },
        setList(){
			if(!this.loading){
				this.loading = true;
				setTimeout(()=>{
					var list = this.allData.splice(0,10);
					list.map((item)=>{
						this.dataList.push(item);
					});
					this.loading = false;
				},1000);
			}
        }
    }
}
</script>
<style lang="scss" scoped>
   @import "./style/moregoods.scss";
</style>